<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
 * Created by PhpStorm.
 * ArticleLog: Administrator
 * Date: 2020/3/14
 * Time: 17:18
 */

namespace app\lnadmin\controller;
use app\core\InitController;
use think\facade\View;
use think\facade\Request;
use app\lnadmin\model\admin\ArticleLog as ArticleLogModel;
use app\lnadmin\model\admin\User as UserModel;
class ArticleLog extends InitController
{

    // 列表
    public function list()
    {
        return View::fetch('articlelog');
    }
    
    // 详情
    public function index_json($limit='15')
    {
        $coreLog = new ArticleLogModel();
        $data = $coreLog->order(['id'=>'desc'])->paginate($limit);  
        $this->result($data);
    }

    // 删除
    public function del()
    { 
        if ($this->request->isPost()) { 
            $param = $this->request->param();
            $result = ArticleLogModel::destroy($param['id']);
            if ($result == true) { 
            add_admin_log('del', '行为日志');// 记录行为日志
                return $this->success('', '', '删除成功');
            }
        }
    }

    //删除一个月前的操作日志
    public function deletelog()
    {
        ArticleLogModel::where('create_time', '<= time', time() - (86400 * 30))->delete();
        $this->success('', '', "删除日志成功！");
    }
}